﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：李刚 
    //
    // 文件名：DistributionToCompany.cs
    // 文件功能描述：本企业所有可配送的产品列表（这里仅有采购产品）
    // 创建标识：李刚2009-05-18
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model.Enum;
using HZ.DrugTrade.Model;

namespace HZ.DrugTrade.Web.Enterprise.RelationQuery
{
    public partial class DistributionToCompany : BasePage
    {
        public DistributionToCompany()
        {
            this.ModuleNo = Module.配送区域管理.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindArea();
                BindDridView();

            }
        }

        /// <summary>
        /// 绑定地区2009-11-20
        /// </summary>
        private void BindArea()
        {

            IBLL_Area iBLL_Area = Factory.BLL_Area();
            string AreaID = CurrentAccount.GetCurrentDeployArea().AreaID;
            IList<Area> list = iBLL_Area.GetAllCity(AreaID);
            this.ddlArea.DataSource = list;
            this.ddlArea.DataTextField = "AreaName";
            this.ddlArea.DataValueField = "AreaID";
            this.ddlArea.DataBind();
            ListItem item = new ListItem();
            item.Text = Constants.ALL_ITEM_TEXT;
            item.Value = Constants.ALL_ITEM_VALUE;
            this.ddlArea.Items.Insert(0, item);
        }

        /// <summary>
        /// 执行筛选
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            BindDridView();
        }


        /// <summary>
        /// 绑定查询
        /// </summary>
        private void BindDridView()
        {
            HZ.DrugTrade.Model.Query.AreaDistribution aDistributionRelation = new HZ.DrugTrade.Model.Query.AreaDistribution();
            aDistributionRelation.CompanyID_PS = CurrentAccount.GetUser().Org.OrgID;
            aDistributionRelation.GoodsName = txtProductName.Text.Trim();
            aDistributionRelation.Outlookc = txtOutlookc.Text.Trim();
            aDistributionRelation.Unit = txtUnit.Text.Trim();
            aDistributionRelation.Material = txtMaterial.Text.Trim();
            aDistributionRelation.PinyinCode = this.txtpinyincode.Text.Trim();
            aDistributionRelation.ProjectID = this.ddlProjectid.SelectedValue;
            aDistributionRelation.CompanyName_SC = txtCompany_SC.Text.Trim();
            //aDistributionRelation.PinyinCode = this.txtPinyinCode.Text.Trim();
            aDistributionRelation.IsUsing = true;//只有不是撤废状态的产品才能进行配送企业查询
            aDistributionRelation.AreaID = ddlArea.SelectedIndex == 0 ? "" : ddlArea.SelectedValue.ToString();
            string Unioncitystateda = ddlUnioncitystateda.SelectedItem.Value;
            string source = "";
            if (!string.IsNullOrEmpty(Unioncitystateda))
            {
                if (Unioncitystateda == "0")
                {
                    source = "Unioncitystateda = '未审核'";
                }
                else if (Unioncitystateda == "1")
                {
                    source = "Unioncitystateda = '审核通过'";
                }
                else if (Unioncitystateda == "2")
                {
                    source = "Unioncitystateda = '审核不通过'";
                }
                aDistributionRelation.Append = source;
            }
            aDistributionRelation.CompanyName_TB = txtCompany_ZB.Text.Trim();
            aDistributionRelation.SortFields = " GoodsName asc,ProcureCataLogID,areaid,companyid_ps";

            int totalCount = 0;
            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            IBLL_Distribution distributionCtrl = Factory.BLL_Distribution();
            IList<HZ.DrugTrade.Model.View.AreaDistribution> distibutionRelationList = distributionCtrl.GetAreaDistribution(aDistributionRelation, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;

            GvRelaion.DataSource = distibutionRelationList;
            GvRelaion.DataBind();



            if (GvRelaion.Rows.Count <= 0)
            {
                btnExport.Visible = false;
            }
        }

        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            BindDridView();
        }


        /// <summary>
        /// 简单查询与高级查询的转换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbnSwitch_Click(object sender, EventArgs e)
        {
            if (lbnSwitch.CommandArgument == "simple")
            {
                ltlAdvance.Text = "";
                lbnSwitch.CommandArgument = "advance";
                lbnSwitch.Text = "简单查询";
            }
            else
            {
                ltlAdvance.Text = "<tbody id='advance' style='display:none'>";
                lbnSwitch.CommandArgument = "simple";
                lbnSwitch.Text = "高级查询";

                //清空数据

                //cbxProjectName.SelectedIndex = 0;
                txtCompany_ZB.Text = "";
                ddlArea.SelectedIndex = 0;
                ddlUnioncitystateda.SelectedIndex = 0;

                //txtProcurePrice.Text = "";
                //txtGoodsName.Text="";

                //txtOperateTimeBegin.Text = "";
                //txtOperateTimeEnd.Text = "";
                //dtProcureBeginTimeBegin.Text = "";
                //dtProcureBeginTimeEnd.Text = "";
                //dtProcureEndTimeBegin.Text = "";
                //dtProcureEndTimeEnd.Text = "";

            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            HZ.DrugTrade.Model.Query.AreaDistribution aDistributionRelation = new HZ.DrugTrade.Model.Query.AreaDistribution();
            aDistributionRelation.CompanyID_PS = CurrentAccount.GetUser().Org.OrgID;
            aDistributionRelation.GoodsName = txtProductName.Text.Trim();
            aDistributionRelation.Material = txtMaterial.Text.Trim();
            aDistributionRelation.Outlookc = txtOutlookc.Text.Trim();
            aDistributionRelation.ProjectID = this.ddlProjectid.SelectedValue;
            aDistributionRelation.Unit = txtUnit.Text.Trim();
            aDistributionRelation.PinyinCode = this.txtpinyincode.Text.Trim();
            aDistributionRelation.CompanyName_SC = txtCompany_SC.Text.Trim();
            //aDistributionRelation.PinyinCode = this.txtPinyinCode.Text.Trim();
            string Unioncitystateda = ddlUnioncitystateda.SelectedItem.Value;
            string source = "";
            if (!string.IsNullOrEmpty(Unioncitystateda))
            {
                if (Unioncitystateda == "0")
                {
                    source = "Unioncitystateda = '未审核'";
                }
                else if (Unioncitystateda == "1")
                {
                    source = "Unioncitystateda = '审核通过'";
                }
                else if (Unioncitystateda == "2")
                {
                    source = "Unioncitystateda = '审核不通过'";
                }
                aDistributionRelation.Append = source;
            }
            aDistributionRelation.CompanyName_TB = txtCompany_ZB.Text.Trim();
            aDistributionRelation.SortFields = " GoodsName asc";

            int totalCount = 0;
            IBLL_Distribution distributionCtrl = Factory.BLL_Distribution();
            IList<HZ.DrugTrade.Model.View.AreaDistribution> distibutionRelationList = distributionCtrl.GetAreaDistribution(aDistributionRelation, 1, 0, out totalCount);

            DataTable dt = HZ.Data.ModelConvert.GetDataTableFromModel(distibutionRelationList);

            HZ.Excel.ExcelHelper.ExportDataForWeb(dt, GvRelaion);
        }

        protected void GvRelaion_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                if (ddlProjectid.SelectedItem.Value == "0002")
                {
                    e.Row.Cells[e.Row.Cells.Count-3].Text = "自主报价";
                }
                else
                {
                    e.Row.Cells[e.Row.Cells.Count-3].Text = "采购限价";
                }
            }
        }
    }
}
